import VXETable from 'vxe-table'
import createBem from '@Components/assets/js/utils/bem'
import { tableNamespace } from '../../../config'
import { handlePropsMethod } from '../../../utils'
import './index.scss'

const Bem = createBem(`${tableNamespace}__input`)

VXETable.renderer.add('Input', {
  autofocus: '.el-input__inner',
  renderEdit(h, renderOpts, params) {
    const { options = {} } = renderOpts
    const { row, column, $table } = params

    const _options = handlePropsMethod(options, params, ['disabled'])

    return [
      <el-input
        class={Bem()}
        v-model={row[column.property]}
        onInput={() => {
          $table.updateStatus(params)
        }}
        size={this.$store.getters.size}
        props={_options}
      />
    ]
  },
  renderCell(h, renderOpts, params) {
    const { formatter } = renderOpts
    const { row, column } = params
    const cellValue = row[column.property]
    const content = formatter
      ? formatter({ cellValue, row, column })
      : cellValue

    return [<span>{content}</span>]
  }
})

/** @type { Column } */
export const options = {
  showOverflow: 'tooltip',
  align: 'left'
}
